<#include "/lib/blog_lib.html"/>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <link rel="apple-touch-icon" sizes="76x76" href="${request.contextPath}/assets/img/apple-icon.png">
    <link rel="icon" type="image/png" href="${request.contextPath}/favicon.ico">

    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>房源中心-重庆房屋出租咨询有限公司</title>
    <meta name="keyword" content="重庆房屋出租咨询有限公司,箭乔,上海,投资" />
    <meta name="description" content="重庆房屋出租咨询有限公司" />
    <link href="${request.contextPath}/bootstrap3/css/bootstrap.css" rel="stylesheet" />
    <link href="${request.contextPath}/assets/css/demo.css" rel="stylesheet" />
    <!--     Font Awesome     -->
    <link href="${request.contextPath}/bootstrap3/css/font-awesome.css" rel="stylesheet">
    <link href='http://fonts.googleapis.com/css?family=Grand+Hotel' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="${request.contextPath}/assets/css/product.css">
</head>
<body>
<nav id="navbar" class="navbar navbar-fixed-top">
<@nav_menu/>
</nav>

<div class="main">
    <div class="container" style="padding-top:135px">
        <div id="search">
                <div class="input-group input-group-lg">
                    <input id="searchText" type="text" class="form-control" placeholder="搜索产品" value="${search!}">
                    <span class="input-group-btn">
                    <button class="btn btn-default" type="button" id="searchBtn">搜索</button>
                    </span>
                </div>
        </div>
        <div id="select">
            <ul class="select">
                <li class="select-list">
                    <dl id="select1">
                        <dt>房屋类型：</dt>
                        <dd class="select-all"><a href="#">不限</a></dd>
                        <#list companies as companie>
                            <dd><a href="javascript:;" data-name="companyType" data-value="${companie.id!}">${companie.companyType!}</a></dd>
                        </#list>
                    </dl>
                </li>
                <li class="select-list">
                    <dl id="select2">
                        <dt>房屋价格：</dt>
                        <dd class="select-all"><a href="#">不限</a></dd>
                        <dd><a href="javascript:;" data-name="regCapital" data-value="1">小于100元</a></dd>
                        <dd><a href="javascript:;" data-name="regCapital" data-value="2">100元-500元</a></dd>
                        <dd><a href="javascript:;" data-name="regCapital" data-value="3">500元-1000元</a></dd>
                        <dd><a href="javascript:;" data-name="regCapital" data-value="4">1000元-5000元</a></dd>
                        <dd><a href="javascript:;" data-name="regCapital" data-value="5">5000元以上</a></dd>
                    </dl>
                </li>
                <li class="select-list">
                    <dl id="select3">
                        <dt>房屋年限：</dt>
                        <dd class="select-all"><a href="#">不限</a></dd>
                        <dd><a href="javascript:;" data-name="regYear" data-value="1">小于1年</a></dd>
                        <dd><a href="javascript:;" data-name="regYear" data-value="2">1年-3年</a></dd>
                        <dd><a href="javascript:;" data-name="regYear" data-value="3">3年-5年</a></dd>
                        <dd><a href="javascript:;" data-name="regYear" data-value="4">5年-10年</a></dd>
                        <dd><a href="javascript:;" data-name="regYear" data-value="5">10年以上</a></dd>
                    </dl>
                </li>
                <li class="select-list">
                    <dl id="select4">
                        <dt>房屋地址：</dt>
                        <dd class="select-all"><a href="#">不限</a></dd>
                        <#list regAddresses as regAddresse>
                            <dd><a href="javascript:;" data-name="city" data-value="${regAddresse.id!}">${regAddresse.city!}</a></dd>
                        </#list>
                    </dl>
                </li>
                <li class="select-result" id="select-result" style="display: none">
                    <dl>
                        <dt>已选条件：</dt>
                        <dd class="select-no" style="display: none;">暂时没有选择过滤条件</dd>
                    </dl>
                </li>
            </ul>
        </div>
        <div id="sort">
            <ul class="list-inline" style="padding-left: 24px;padding-top: 12px;padding-bottom: 12px">
                <li><a href="javascript:;" data-name="all" data-value="up">综合排序</a></li>
                <li><a href="javascript:;" data-name="orderby_regDate" data-value="up">时间排序<span class="glyphicon"></span></a></li>
                <li><a href="javascript:;" data-name="orderby_regCapital" data-value="up">价格排序<span class="glyphicon"></span></a></li>
            </ul>
        </div>
        <div id="product">
            <#if (products.records?size==0)>
                <h1>没有相关的房屋信息</h1>
                <#else>
                    <#list products.records as item>
                        <div class="product">
                            <div>
                                <#if (item.productImg??)>
                                    <#list item.productImg?split("|") as itemImg>
                                        <#if itemImg??>
                                            <#assign productImg = itemImg>
                                        <#break>
                                        </#if>
                                    </#list>
                                    <img src="/${productImg}" alt="重庆房屋出租咨询有限公司" width="400px" height="280px" alt="">
                                    <#else>
                                        <img src="img/product.png" alt="重庆房屋出租咨询有限公司" width="400px" height="280px" alt="">
                                </#if>
                            </div>
                            <div>
                                <span>房屋信息: ${item.productName!}</span> <br>
                                <span>房屋地址: ${item.city!}</span> <br>
                                <span>房屋价格: ${item.regCapital!}元</span> <br>
                                <span>房屋年限: ${item.regDate!}</span> <br>
                                <span>房屋面积: ${item.operatingPeriod!}</span> <br>
                                <span style="width: 590px;height: 128px;display: inline-block;overflow: hidden;">房屋特色: ${item.advantage!}</span> <br>
                            </div>
                            <div class="pull-right">
                                <p><i class="glyphicon glyphicon-calendar"></i> ${item.gmtCreate?date!}</p>
                                <br>
                                <a href="/product/${item.id!}.html" class="pull-right selectDetails">查看详情</a>
                                <div class="clearfix"></div>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </#list>
            </#if>
        </div>

        <div class="text-center">
            <ul class="pagination ct-blue">
                <#if products.pages!=0>
                <@page products.current products.pages 6 "pagehelper"/>
                <#else>
                    <li class="active"><a href="javascript:;">1</a></li>
                </#if>
            </ul>
        </div>
    </div>
</div>

<@footer1/>
</body>
<script src="${request.contextPath}/js/jquery.min.js" type="text/javascript"></script>
<script src="${request.contextPath}/bootstrap3/js/bootstrap.js" type="text/javascript"></script>
<script src="${request.contextPath}/assets/js/custom.js"></script>
<script>
    window.onscroll=function(){
        var sl=-Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
        document.getElementById('navbar').style.left=sl+'px';

    };
    // URL 参数获取
    function getQueryString(name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return null;
    }

    // 显示隐藏条件
    function showHide() {
        if ($(".select-result dd").length > 1) {
            $(".select-no").hide();
        } else {
            $(".select-no").show();
        }
    }

    // 初始化界面
    initPage();
    function initPage() {
        var companyType = getQueryString("companyType");
        if (companyType != null) {
            $("#select1 dd").removeClass("selected");
            $("#select1 dd [data-value='"+companyType+"']").parent().addClass("selected");
            var copy = $("#select1 dd [data-value='"+companyType+"']").parent().clone();
            $(".select-result dl").append(copy.attr("id", "selectA"));
        } else {
            $("#select1 .select-all").addClass("selected");
        }

        var regCapital = getQueryString("regCapital");
        if (regCapital != null) {
            $("#select2 dd").removeClass("selected");
            $("#select2 dd [data-value='"+regCapital+"']").parent().addClass("selected");
            var copy = $("#select2 dd [data-value='"+regCapital+"']").parent().clone();
            $(".select-result dl").append(copy.attr("id", "selectB"));
        } else {
            $("#select2 .select-all").addClass("selected");
        }

        var regYear = getQueryString("regYear");
        if (regYear != null) {
            $("#select3 dd").removeClass("selected");
            $("#select3 dd [data-value='"+regYear+"']").parent().addClass("selected");
            var copy = $("#select3 dd [data-value='"+regYear+"']").parent().clone();
            $(".select-result dl").append(copy.attr("id", "selectC"));
        } else {
            $("#select3 .select-all").addClass("selected");
        }

        var city = getQueryString("city");
        if (city != null) {
            $("#select4 dd").removeClass("selected");
            $("#select4 dd [data-value='"+city+"']").parent().addClass("selected");
            var copy = $("#select4 dd [data-value='"+city+"']").parent().clone();
            $(".select-result dl").append(copy.attr("id", "selectD"));
        } else {
            $("#select4 .select-all").addClass("selected");
        }

        var search = getQueryString("search");
        if (search != null) {
            var html = '<dd class="selectS" id="selectS">' +
                    '<a href="javascript:;" data-name="search" data-value="${search!}">${search!}</a>' +
                    '</dd>';
            $(".select-result dl").append(html);
        }

        // 排序
        var all = getQueryString("all");
        if (all != null) {
            var html = '<dd class="selectO" id="selectO">' +
                    '<a href="javascript:;" data-name="all" data-value="'+all+'">'+all+'</a>' +
                    '</dd>';
            $("#sort li [data-name='all']").parent().addClass("sortActive");
            $(".select-result dl").append(html);
        }

        var orderby_regDate = getQueryString("orderby_regDate");
        if (orderby_regDate != null) {
            var html = '<dd class="selectO" id="selectO">' +
                    '<a href="javascript:;" data-name="orderby_regDate" data-value="'+orderby_regDate+'">'+orderby_regDate+'</a>' +
                    '</dd>';
            $("#sort li [data-name='orderby_regDate']").parent().addClass("sortActive");
            var $span = $("#sort li [data-name='orderby_regDate']").find("span");
            if ("up" == orderby_regDate) {
                $span.addClass("glyphicon-arrow-up");
            } else {
                $span.addClass("glyphicon-arrow-down");
            }
            $(".select-result dl").append(html);
        }

        var orderby_regCapital = getQueryString("orderby_regCapital");
        if (orderby_regCapital != null) {
            var html = '<dd class="selectO" id="selectO">' +
                    '<a href="javascript:;" data-name="orderby_regCapital" data-value="'+orderby_regCapital+'">'+orderby_regCapital+'</a>' +
                    '</dd>';
            $("#sort li [data-name='orderby_regCapital']").parent().addClass("sortActive");
            var $span = $("#sort li [data-name='orderby_regCapital']").find("span");
            if ("up" == orderby_regCapital) {
                $span.addClass("glyphicon-arrow-up");
            } else {
                $span.addClass("glyphicon-arrow-down");
            }
            $(".select-result dl").append(html);
        }

        var current = getQueryString("current");
        if (current != null) {
            $("#selectP").remove();
            var html = '<dd class="selectP" id="selectP">' +
                    '<a href="javascript:;" data-name="current" data-value="'+current+'">'+current+'</a>' +
                    '</dd>';
            $(".select-result dl").append(html);
        }

        showHide();
    }

    var url = "?";
    // 重定向 URL跳转
    function redirect() {
        url = "?";
        console.log($(".select-result dl a"));
        var allSelect = $(".select-result dl a");
        for (var i = 0; i < allSelect.length; i++) {
            var $temp = $(allSelect[i]);
            var dataName = $temp.attr("data-name");
            var dataValue = $temp.attr("data-value");
            url += dataName+"="+dataValue+"&";
        }
        url = url.substring(0, url.length-1);
        window.location.href="/product.html"+url;
    }

    $(document).ready(function(){

        $("#select1 dd").click(function () {
            $("#selectA").remove();
            if ($(this).hasClass("select-all")) {
                $("#selectA").remove();
            } else {
                var copyThisA = $(this).clone();
                if ($("#selectA").length > 0) {
                    $("#selectA").remove();
                    $(".select-result dl").append(copyThisA.attr("id", "selectA"));
                } else {
                    $(".select-result dl").append(copyThisA.attr("id", "selectA"));
                }
            }
            redirect();
        });

        $("#select2 dd").click(function () {
            $("#selectB").remove();
            if ($(this).hasClass("select-all")) {
                $("#selectB").remove();
            } else {
                var copyThisB = $(this).clone();
                if ($("#selectB").length > 0) {
                    $("#selectB").remove();
                    $(".select-result dl").append(copyThisB.attr("id", "selectB"));
                } else {
                    $(".select-result dl").append(copyThisB.attr("id", "selectB"));
                }
            }
            redirect();
        });

        $("#select3 dd").click(function () {
            $("#selectC").remove();
            if ($(this).hasClass("select-all")) {
                $("#selectC").remove();
            } else {
                var copyThisC = $(this).clone();
                if ($("#selectC").length > 0) {
                    $("#selectC").remove();
                    $(".select-result dl").append(copyThisC.attr("id", "selectC"));
                } else {
                    $(".select-result dl").append(copyThisC.attr("id", "selectC"));
                }
            }
            redirect();
        });
        $("#select4 dd").click(function () {
            $("#selectD").remove();
            if ($(this).hasClass("select-all")) {
                $("#selectD").remove();
            } else {
                var copyThisC = $(this).clone();
                if ($("#selectD").length > 0) {
                    $("#selectD").remove();
                    (".select-result dl").append(copyThisC.attr("id", "selectD"));
                } else {
                    $(".select-result dl").append(copyThisC.attr("id", "selectD"));
                }
            }
            redirect();
        });

        $("#searchBtn").click(function () {
            $("#selectS").remove();
            var searchText = $("#searchText").val()
            var html = '<dd class="selectS" id="selectS">' +
            '<a href="javascript:;" data-name="search" data-value="'+searchText+'">'+searchText+'</a>' +
            '</dd>';
            $(".select-result dl").append(html);
            redirect();
        })

        $("#select-result").on("click", '#selectA',function () {
            $(this).remove();
            $("#select1 .select-all").addClass("selected").siblings().removeClass("selected");
            if ($(".select-result dd").length > 1) {
                $(".select-no").hide();
            } else {
                $(".select-no").show();
            }
        });

        $("#select-result").on("click", '#selectB', function () {
            $(this).remove();
            $("#select2 .select-all").addClass("selected").siblings().removeClass("selected");
        });

        $("#select-result").on("click", '#selectC',function () {
            $(this).remove();
            $("#select3 .select-all").addClass("selected").siblings().removeClass("selected");
        });

        $("#select-result").on("click", '#selectD',function () {
            $(this).remove();
            $("#select4 .select-all").addClass("selected").siblings().removeClass("selected");
        });
        $(".select dd").on("click", function () {
            showHide()
        });
        $("#sort li").click(function () {
            $("#sort li").removeClass("sortActive");
            $(this).addClass("sortActive");
            var $span = $(this).find("span");
            var $this = $(this);
            if($span.hasClass("glyphicon-arrow-up")){
                $span.removeClass("glyphicon-arrow-up");
                $span.addClass("glyphicon-arrow-down");
                $this.children().attr("data-value", "down")
                // alert("降序")
            }else{
                $span.removeClass("glyphicon-arrow-down");
                $span.addClass("glyphicon-arrow-up");
                $this.children().attr("data-value", "up")
                // alert("升序")
            }
            var html = '<dd class="selectO" id="selectO">' +
                    '<a href="javascript:;" data-name="'+$this.children().attr("data-name")+'" data-value="'+$this.children().attr("data-value")+'">'+$this.children().attr("data-value")+'</a>' +
                    '</dd>';
            $("#selectO").remove();
            $(".select-result dl").append(html);
            console.log($this.children().attr("data-name") + "  " + $this.children().attr("data-value"))
            redirect();
        })
    });

    function pagehelper(pageNo) {
        $("#selectP").remove();
        var html = '<dd class="selectP" id="selectP">' +
                '<a href="javascript:;" data-name="current" data-value="'+pageNo+'">'+pageNo+'</a>' +
                '</dd>';
        $(".select-result dl").append(html);
        redirect();
    }
</script>
</html>